<template>
  <el-form :model="tableForm" :rules="tableRule" ref="tableForm" label-width="120px">

    <el-descriptions title="评估结果">
    </el-descriptions>
    <el-row>
      <el-col :span="20">
        <el-form-item label="卡号" prop="account">
          <el-input size="small" v-model="tableForm.account" auto-complete="off" placeholder="请输入卡号"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="4">
        <el-popover placement="right" trigger="click" v-model="visible">
          <Selector @getSelectorData="getSelectorData"></Selector>
          <el-button slot="reference">选择</el-button>
        </el-popover>
      </el-col>
    </el-row>

    <el-form-item label="评估分数" prop="score">
      <el-input size="small" v-model="tableForm.score" auto-complete="off" placeholder="请输入评估分数"></el-input>
    </el-form-item>

    <el-form-item label="评估结果" prop="result">
      <el-input size="small" type="textarea" v-model="tableForm.result" auto-complete="off"
                placeholder="请输入评估结果"></el-input>
    </el-form-item>

    <el-descriptions title="档案信息">
      <el-descriptions-item label="姓名">{{ tableForm.name }}</el-descriptions-item>
      <el-descriptions-item label="手机号">{{ tableForm.phone }}</el-descriptions-item>
      <el-descriptions-item label="身份证">{{ tableForm.card }}</el-descriptions-item>
      <el-descriptions-item label="家庭住址">{{ tableForm.address }}</el-descriptions-item>
      <el-descriptions-item label="病史">{{ tableForm.medical }}</el-descriptions-item>
      <el-descriptions-item label="过敏史">{{ tableForm.allergy }}</el-descriptions-item>
      <el-descriptions-item label="药物使用史">{{ tableForm.drug }}</el-descriptions-item>
    </el-descriptions>

    <el-descriptions title="身体指标" style="padding-top: 10px">
    </el-descriptions>
    <el-table :data="physicalData" style="width: 100%">
      <el-table-column align="center" sortable prop="height" label="身高(cm)"></el-table-column>
      <el-table-column align="center" sortable prop="weight" label="体重(kg)"></el-table-column>
      <el-table-column align="center" sortable prop="lowPressure" label="血压(mmHg)">
        <template slot-scope="scope">
          <span>{{ scope.row.lowPressure }}-{{ scope.row.highPressure }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" sortable prop="glucose" label="血糖(mmol/L)"></el-table-column>

      <el-table-column align="center" sortable prop="erythrocyte" label="红细胞"></el-table-column>
      <el-table-column align="center" sortable prop="hemoglobin" label="血红蛋白(g/L)"></el-table-column>
      <el-table-column align="center" sortable prop="leukocyte" label="白细胞"></el-table-column>
      <el-table-column align="center" sortable prop="Neutrophils" label="中性粒细胞比率(%)"></el-table-column>
      <el-table-column align="center" sortable prop="lymphocyte" label="淋巴细胞"></el-table-column>
      <el-table-column align="center" sortable prop="platelet" label="血小板"></el-table-column>
      <el-table-column align="center" sortable prop="total_cholesterol" label="总胆固醇(mmol/L)"></el-table-column>
      <el-table-column align="center" sortable prop="Triglycerides" label="甘油三酯(mmol/L)"></el-table-column>
      <el-table-column align="center" sortable prop="LDL-cholesterol" label="低密度脂蛋白胆固醇(mmol/L)"></el-table-column>
      <el-table-column align="center" sortable prop="HDL_cholesterol" label="高密度脂蛋白胆固醇(mmol/L)"></el-table-column>
      <el-table-column align="center" sortable prop="alanine_transaminase" label="谷丙转氨酶(U/L)"></el-table-column>
      <el-table-column align="center" sortable prop="aspartate_aminotransferase" label="谷草转氨酶(U/L)"></el-table-column>
      <el-table-column align="center" sortable prop="total_bilirubin" label="总胆红素(μ mol/L)"></el-table-column>
      <el-table-column align="center" sortable prop="total_bilirubin_direct" label="直接胆红素(mmol/L)"></el-table-column>
      <el-table-column align="center" sortable prop="pro" label="尿蛋白"></el-table-column>
      <el-table-column align="center" sortable prop="glu" label="尿葡萄糖"></el-table-column>
      <el-table-column align="center" sortable prop="bil" label="尿胆红素"></el-table-column>
      <el-table-column align="center" sortable prop="ket" label="尿胴体"></el-table-column>
      <el-table-column align="center" sortable prop="wbc" label="白细胞(/HP)"></el-table-column>
      <el-table-column align="center" sortable prop="rbc" label="红细胞(/HP)"></el-table-column>
      <el-table-column align="center" sortable prop="uro" label="尿胆原"></el-table-column>
      <el-table-column align="center" sortable prop="sg" label="尿比重"></el-table-column>
      <el-table-column align="center" sortable prop="ph" label="尿酸碱度"></el-table-column>
      <el-table-column align="center" sortable prop="afp" label="甲胎蛋白"></el-table-column>
      <el-table-column align="center" sortable prop="cea" label="癌胚抗原"></el-table-column>
      <el-table-column align="center" sortable prop="fer" label="铁蛋白"></el-table-column>

      <el-table-column align="center" sortable prop="heart" label="心率(次/分)"></el-table-column>
      <el-table-column align="center" sortable prop="createDate" label="记录日期"></el-table-column>
    </el-table>

    <el-descriptions title="就诊记录" style="padding-top: 10px">
    </el-descriptions>
    <el-table :data="pharmacyData" style="width: 100%">
      <el-table-column align="center" sortable prop="name" label="药物名称"></el-table-column>
      <el-table-column align="center" sortable prop="createDate" label="服用时间"></el-table-column>
      <el-table-column align="center" sortable prop="info" label="使用说明"></el-table-column>
      <el-table-column align="center" sortable prop="endDate" label="记录日期"></el-table-column>
    </el-table>

    <el-descriptions title="用药记录" style="padding-top: 10px">
    </el-descriptions>
    <el-table :data="medicalData" style="width: 100%">
      <el-table-column align="center" sortable prop="createDate" label="就诊时间"></el-table-column>
      <el-table-column align="center" sortable prop="hospital" label="就诊医院"></el-table-column>
      <el-table-column align="center" sortable prop="info" label="就诊主诉"></el-table-column>
      <el-table-column align="center" sortable prop="result" label="诊断结果"></el-table-column>
      <el-table-column align="center" sortable prop="suggest" label="诊断建议"></el-table-column>
    </el-table>


  </el-form>
</template>

<script>

import {addData, updateData, getPhysicalData, getPharmacyData, getMedicalData, getScoreData} from '@/api/assess'
import Selector from '../user/selector'

// 表单校验
const tableRule = {
  account: [{required: true, message: '请输入卡号', trigger: 'blur'}],
  score: [{required: true, message: '请输入评估分数', trigger: 'blur'}],
};

// 请求数据用户
const searchForm = {
  currentPage: 1,
  pageSize: 200,
  userId: '',
  account: ''
}

export default {
  name: 'AssessEdit',
  props: {
    formData: {
      type: Object
    }
  },
  data() {
    return {
      tableForm: this.formData,
      tableRule: tableRule,
      visible: false,
      searchForm: searchForm,
      physicalData: [],
      pharmacyData: [],
      medicalData: []
    }
  },
  components: {
    Selector
  },
  created() {
    this.searchForm.userId = this.formData.userId
    this.refreshData()
  },
  methods: {
    //表单保存事件
    submitForm() {
      this.$refs["tableForm"].validate(valid => {
        if (valid) {
          if (this.tableForm.id == "") {
            addData(this.tableForm).then(res => {
              if (res.message == "success") {
                this.$message({
                  type: 'success',
                  message: '新增成功！'
                });
                this.$emit("closeDialog", false);
              } else {
                this.$message({
                  type: 'info',
                  message: res.message
                });
              }
            });
          } else {
            updateData(this.tableForm).then(res => {
              if (res.message == "success") {
                this.$message({
                  type: 'success',
                  message: '修改成功！'
                });
                this.$emit("closeDialog", false);
              } else {
                this.$message({
                  type: 'info',
                  message: res.message
                });
              }
            });
          }
        } else {
          return false;
        }
      });
    },
    // 选择父表数据
    getSelectorData(v) {
      this.visible = false
      this.searchForm.userId = v[0].id

      this.tableForm.account = v[0].account
      this.tableForm.userId = v[0].id
      this.tableForm.name = v[0].name
      this.tableForm.phone = v[0].phone
      this.tableForm.card = v[0].card
      this.tableForm.address = v[0].address
      this.tableForm.medical = v[0].medical
      this.tableForm.allergy = v[0].allergy
      this.tableForm.drug = v[0].drug

      this.refreshData()
    },
    refreshData() {
      getPhysicalData(this.searchForm).then(res => {
        this.physicalData = res.body.records
      })

      getPharmacyData(this.searchForm).then(res => {
        this.pharmacyData = res.body.records
      })

      getMedicalData(this.searchForm).then(res => {
        this.medicalData = res.body.records
      })

      getScoreData(this.searchForm).then(res => {
        let data = res.body
        this.tableForm.score = data.score
        this.tableForm.result = data.result

      })
    },
    clearForm() {
      this.$refs.tableForm.resetFields();
      this.$refs.tableForm.clearValidate();
    }
  }
}
</script>

<style scoped>


</style>
